#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@file: java_full_version_test.py
@author: lyndon
@time: Created on 2022-03-23 16:53
@env: Python
@desc:
@ref:
@blog:
"""
import unittest
import os
import subprocess
# from time import sleep
#
# print('start...')
# print('sleep')
# sleep(2)
# print('stop')


def get_java_version():
    java_home = os.getenv("JAVA_HOME")
    java_res = subprocess.Popen([java_home + "/bin/java", "-fullversion"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    out, err = java_res.communicate()

    if java_res.returncode == 0:
        return out.decode('utf-8').replace("\"", "\\\"").strip()
    return "unknown jdk"


class OutputJavaFullVersion(unittest.TestCase):
    def test_str_replace(self):
        java_version = get_java_version()
        print("java_version:%s" % java_version)

